package com.project.frba.bi.extraction.database;

import java.util.List;

import com.project.frba.bi.extraction.ExtractionResult;

public class DatabaseResult implements ExtractionResult {
	
	private List<ExtractionRow> result;
	private Integer index = 0;
	
	public DatabaseResult(List<ExtractionRow> result){
		this.result = result;
	}

	public boolean hasNext() {
		if(index + 1 < result.size()){
			return true;
		}
		return false;
	}

	public void next() {
		index++;
	}

	public <T> T getValue(String key, Class<T> returnType){
		ExtractionRow row = result.get(index);
		Object keyObject = row.getValue(key);
		
		if(keyObject != null){
			return returnType.cast(keyObject);
		}
		return null;
	}

	public Long getMetric() {
		return this.getValue("metric", Long.class);
	}

}
